/**
 *******************************************************************************
 * @FileName  : svc_handle.h
 * @Author    : GaoQiu
 * @CreateDate: 2020-05-18
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */
#ifndef SVC_HANDLE_H_
#define SVC_HANDLE_H_

#include "stack/host/dm_api.h"
#include "stack/host/att_api.h"

/* GAP */
#define GAP_START_HDL               0x01
#define GAP_END_HDL                 (GAP_MAX_HDL  - 1)

/* GATT */
#define GATT_START_HDL              6//(GAP_END_HDL  + 1)
#define GATT_END_HDL                (GATT_MAX_HDL - 1)

/* Battery */
#define BATT_START_HDL              10//(GATT_END_HDL + 1)
#define BATT_END_HDL                (BATT_MAX_HDL - 1)

/* HID */
#define HID_START_HDL               20//14//(BATT_END_HDL + 1)
#define HID_END_HDL                 (HID_MAX_HDL  - 1)

/* Custom */
#define GW_SVC_START_HDL            60//50//(HID_END_HDL  + 1)
#define GW_SVC_END_HDL              (GW_MAX_HDL   - 1)

/* HTS */
#define HTS_SVC_START_HDL           70//58//(GW_SVC_END_HDL + 1)
#define HTS_SVC_END_HDL             (HTS_MAX_HDL - 1)

/* DFU */
#define DFU_SVC_START_HDL           80//62//(HTS_SVC_END_HDL + 1)
#define DFU_SVC_END_HDL             (DFU_MAX_HDL - 1)

/* Throughput */
#define THROUGHPUT_SVC_START_HDL    90
#define THROUGHPUT_SVC_END_HDL      (THROUGHPUT_MAX_HDL - 1)

/* GAP ATT Handles */
enum{
	GAP_SVC_HDL = GAP_START_HDL,
	GAP_DEVICE_NAME_CH_HDL,
	GAP_DEVICE_NAME_HDL,
	GAP_APPEARANCE_CH_HDL,
	GAP_APPEARANCE_HDL,
	GAP_MAX_HDL,
};


/* GATT ATT Handles */
enum
{
  GATT_SVC_HDL = GATT_START_HDL,    /*!< GATT service declaration */
  GATT_SC_CH_HDL,                   /*!< Service changed characteristic */
  GATT_SC_HDL,                      /*!< Service changed */
  GATT_SC_CH_CCC_HDL,               /*!< Service changed client characteristic configuration descriptor */
  GATT_MAX_HDL                      /*!< GATT maximum handle */
};


/* Battery ATT Handles */
enum{
	BATT_SVC_HDL = BATT_START_HDL,
	BATT_LVL_CH_HDL,
	BATT_LVL_HDL,
	BATT_LVL_CH_CCC_HDL,
	BATT_MAX_HDL,
};


/* HID ATT Handle */
enum
{
  //12
  HID_SVC_HDL = HID_START_HDL,        /*!< Proprietary Service Declaration */

  HID_INFO_CH_HDL,                    /*!< HID Information Characteristic Declaration */
  HID_INFO_HDL,                       /*!< HID Information Value */

  HID_REPORT_MAP_CH_HDL,              /*!< HID Report Map Characteristic Declaration */
  HID_REPORT_MAP_HDL,                 /*!< HID Report Map Value */
  HID_EXTERNAL_REPORT_HDL,            /*!< HID External Report Descriptor */

  HID_CONTROL_POINT_CH_HDL,           /*!< HID Control Point Characteristic Declaration */
  HID_CONTROL_POINT_HDL,              /*!< HID Control Point Value */

  HID_KEYBOARD_BOOT_IN_CH_HDL,        /*!< HID Keyboard Boot Input Characteristic Declaration */
  HID_KEYBOARD_BOOT_IN_HDL,           /*!< HID Keyboard Boot Input Value */
  HID_KEYBOARD_BOOT_IN_CH_CCC_HDL,    /*!< HID Keyboard Boot Input CCC Descriptor */

  HID_KEYBOARD_BOOT_OUT_CH_HDL,       /*!< HID Keyboard Boot Output Characteristic Declaration */
  HID_KEYBOARD_BOOT_OUT_HDL,          /*!< HID Keyboard Boot Output Value */

  HID_MOUSE_BOOT_IN_CH_HDL,           /*!< HID Mouse Boot Input Characteristic Declaration */
  HID_MOUSE_BOOT_IN_HDL,              /*!< HID Mouse Boot Input Value */
  HID_MOUSE_BOOT_IN_CH_CCC_HDL,       /*!< HID Mouse Boot Input CCC Descriptor */

  HID_INPUT_REPORT_1_CH_HDL,          /*!< HID Input Report Characteristic Declaration */
  HID_INPUT_REPORT_1_HDL,             /*!< HID Input Report Value */
  HID_INPUT_REPORT_1_CH_CCC_HDL,      /*!< HID Input Report CCC Descriptor */
  HID_INPUT_REPORT_1_REFERENCE_HDL,   /*!< HID Input Report Reference Descriptor */

  HID_INPUT_REPORT_2_CH_HDL,          /*!< HID Input Report Characteristic Declaration */
  HID_INPUT_REPORT_2_HDL,             /*!< HID Input Report Value */
  HID_INPUT_REPORT_2_CH_CCC_HDL,      /*!< HID Input Report CCC Descriptor */
  HID_INPUT_REPORT_2_REFERENCE_HDL,   /*!< HID Input Report Reference Descriptor */

  HID_INPUT_REPORT_3_CH_HDL,          /*!< HID Input Report Characteristic Declaration */
  HID_INPUT_REPORT_3_HDL,             /*!< HID Input Report Value */
  HID_INPUT_REPORT_3_CH_CCC_HDL,      /*!< HID Input Report CCC Descriptor */
  HID_INPUT_REPORT_3_REFERENCE_HDL,   /*!< HID Input Report Reference Descriptor */

  HID_OUTPUT_REPORT_CH_HDL,           /*!< HID Output Report Characteristic Declaration */
  HID_OUTPUT_REPORT_HDL,              /*!< HID Output Report Value */
  HID_OUTPUT_REPORT_REFERENCE_HDL,    /*!< HID Output Report Reference Descriptor */

  HID_FEATURE_REPORT_CH_HDL,          /*!< HID Feature Report Characteristic Declaration */
  HID_FEATURE_REPORT_HDL,             /*!< HID Feature Report Value */
  HID_FEATURE_REPORT_REFERENCE_HDL,   /*!< HID Feature Report Reference Descriptor */

  HID_PROTOCOL_MODE_CH_HDL,           /*!< HID Protocol Mode Characteristic Declaration */
  HID_PROTOCOL_MODE_HDL,              /*!< HID Protocol Mode Value */

  HID_MAX_HDL                         /*!< Maximum handle. */
};


/* GW ATT Handles */
enum{
	//48
	/*<! GuoWang Service */
	GW_SERVICE_DECLARE_HDL = GW_SVC_START_HDL,

	GW_RX_CHAR_DECLARE_HDL,
	GW_RX_VALUE_HDL,
	GW_RX_USER_DESC_HDL,

	GW_TX_CHAR_DECLARE_HDL,
	GW_TX_VALUE_HDL,
	GW_TX_CH_CCC_HDL,
	GW_TX_USER_DESC_HDL,

	GW_MAX_HDL,
};

/* HTS ATT Handles */
enum{
	HTS_SVC_HDL          = HTS_SVC_START_HDL,
	HTS_TEMP_MEAS_CH_HDL,
	HTS_TEMP_MEAS_VAL_HDL,
	HTS_TEMP_MEAS_CH_CCC_HDL,   /*!< client characteristic configuration descriptor*/

	HTS_MAX_HDL,
};

/* DFU ATT Handles */
enum{
	DFU_SVC_HDL = DFU_SVC_START_HDL,

	DFU_CTRL_POINT_CH_HDL,
	DFU_CTRL_POINT_VAL_HDL,
	DFU_CTRL_POINT_CCCD_HDL,

	DFU_PKT_CH_HDL,
	DFU_PKT_VAL_HDL,
	DFU_PKT_CCCD_HDL,

	DFU_MAX_HDL,
};

/* Throughput ATT Handles */
enum{
	THROUGHPUT_SVC_HDL = THROUGHPUT_SVC_START_HDL,

	THROUGHPUT_CH_HDL,
	THROUGHPUT_VAL_HDL,

	THROUGHPUT_MAX_HDL,
};

extern AttsGroup_t gapGrp;
extern AttsGroup_t gattGrp;
extern AttsGroup_t battGrp;
extern AttsGroup_t hidGrp;
extern AttsGroup_t gwGrp;
extern AttsGroup_t htsGrp;
extern AttsGroup_t dfuGrp;
extern AttsGroup_t throughputGrp;

enum{
	BATT_LVL_CCC_IDX           = 1,

	HID_INPUT_REPORT_1_CCC_IDX = 4,
	HID_INPUT_REPORT_2_CCC_IDX = 5,
	HID_INPUT_REPORT_3_CCC_IDX = 6,

	GW_TX_CCC_IDX              = 7,
	HTS_TEMP_MEAS_CCC_IDX      = 8,

	DFU_CTR_POINT_CCC_IDX      = 9,
	DFU_PKT_CCC_IDX            = 10,

	CCC_IDX_MAX,
};
extern AttsCccSets_t ServerCccSets[];

extern uint32_t A_rx_pkt_cnt;
extern uint32_t A_tx_pkt_cnt;


/* GAP API */
void GAP_SetDeviceName(char *name);

/* BAS API */
uint8_t BAS_UpdBattLevel(uint16_t connHandle);

/* HID API */
uint8_t HID_SendKeyboardValue(uint16_t connHandle, uint8_t *pvalue, uint32_t len);
uint8_t HID_SendCustomValue(uint16_t connHandle, uint8_t *pvalue, uint32_t len);
uint8_t HID_SendMouseValue(uint16_t connHandle, uint8_t *pvalue, uint32_t len);

void HID_MouseTestReset(void);
void HID_MoueTestStart(uint16_t connHande);

/* GW API */
uint8_t GW_SendData(uint16_t connHandle, uint8_t *pData, uint32_t len);

/* HTS API */
uint8_t HTS_TempUpd(uint16_t connHandle);

#endif /* SVC_HANDLE_H_ */
